home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn RISC PD-CD 1
/
Acorn RISC PD-CD 1.iso
/
fractals
/
_tripatron
/
mandtext
< prev
next >
Wrap
Text File
|
1990-05-15
|
6KB
|
141 lines
The Complete Dobbers Guide to Mind Bending Mandelbrots.
=======================================================
The idea behind the mandelbrot is to measure the 'escape time' of a chaotic function.
As the numbers are ploughed into the function over and over again, they fluctuate in output
value until, eventually, they start to shoot off towards BIG-numbersville, Arizona. You are
measuring the number of iterations needed for the function Z=Z*Z+C (where z,c are complex
numbers) to head off towards BIG-numbersville, Arizona. To produce a picture in a 2D plane
(your computer screen) you just vary the real and imaginary values of C and count the
iterations, work out an appropriate colour and plot a point. It's so simple, it's stupid!!
First work out Z*Z:
(a+ib)(a+ib) = a*a + a*b*i + a*b*i + b*b*i*i
= a*a + 2*a*b*i - b*b
--------------------->
so the formula is...
zreal = zreal * zreal - zimag * zimag + creal
zimag = 2 * zreal * zimag + cimag
and repeat this calculation until it gets big. The definition of big will be magnitude greater
than 2, as smaller numbers can keep fluctuating. Also keep a counter as some numbers can
fluctuate forever, which can really toss up the calculations. If the counter gets too big,
stop calculating and go on to the next one.
And now write the program... This is written in generic basic. I don't know how to
plot a pixel of a given colour on your computer, so I will call the function
pixel(xpos,ypos,colour) and leave you to work it out. Also a function to turn on a graphics
mode I shall call graphics(). If your version of BASIC doesn't like lower case letters, use
upper case instead, stupid.
10 graphics()
10 startreal = 0.109375000
20 startimag = 0.615234375
30 magnify = 400
40 picwidth = 100
50 picheight = 100
60 countermax = 64
70 FOR y = 0 TO picheight
80 FOR x = 0 TO picwidth
90 creal = x / magnify + startreal
100 cimag = y / magnify + startimag
110 zreal = 0
120 zimag = 0
130 counter = 0
140 REPEAT
150 zreal2 = zreal * zreal
160 zimag2 = zimag * zimag
170 dummy = zreal2 - zimag2 + creal
180 zimag = 2 * zreal * zimag + cimag
190 zreal = dummy
200 counter = counter + 1
210 UNTIL (zreal2 + zimag2 > 4) OR (counter = countermax)
220 pixel(x,y,counter)
230 NEXT x
240 NEXT y
250 END
startreal,startimag are the coordinates of the bottom left of the image on the complex
plane, usually somewhere in the range [-2,2]. magnify is the magnification factor which can be
of the order of thousands. picheight,picwidth is the number of pixels the image is made of and
countermax is the maximum number of iterations allowed. By setting countermax to a low value,
the picture will be quickly drawn but will not be very crinkly. It is useful to keep this
value low (about 16 or 32) when searching for something to look at and crank it up for a full
picture. When you do this, don't forget to change the colour selection to make the picture
intelligable. To do this as described below.
The real art to these pictures is the colour selection. If you only have 16 colours,
you can set countermax to 255 and use:
...
pixel(x,y,counter/16)
...
to spread out the colour bands. In black and white, the best idea is to use bands of black and
white by using:
...
pixel(x,y,(counter/16)MOD2)
...
which both spreads out the colours and sets the pixel colour to either 1 to 0. This method can
be used with 16 colour graphics again by using:
...
pixel(x,y,counter MOD 16)
...
which will give you bands of 0..15,0..15 over and over again. MOD n just finds the remainder
in a division and is useful for repeating sections of 0..n again and again with a rising
counter.
To get other pretty pictures, try altering the values of startreal and startimag,
using magnify to zoom in. Some suggested values are:
startreal startimag magnify
=======================================
-0.3984375 0.64546875 600
-0.935078125 0.253671875 600
-0.681171875 0.43992187 600
0.438801331 -0.39064172 2000
If you're feeling really wacky, another set of pictures that are cool can be generated
by keeping C constant and varying the start values for Z over the picture. This is done by
rewriting these lines...
90 creal = startreal
100 cimag = startimag
110 zreal = (x-(picwidth/2)) / magnify
120 zimag = (y-(picheight/2)) / magnify
These shapes are called Julia sets, as used by The Shamen, and they're best done in
black and white, but the colour bands are cool.
Finally, a strange quickie. It's called POPCORN.
10 graphics()
50 col = 0
60 h=.1
70 FOR j=1TO50
80 FOR k=1TO50
90 xo=-6+.24*j
100 yo=-6+.24*k
110 x=xo
120 y=yo
130 FOR n=1TO50
140 xx=x-h*SIN(y+TAN(3*y))
150 yy=y-h*SIN(x+TAN(3*x))
160 x=xx
170 y=yy
180 jp = 4.166*x+25
190 kp = 4.166*y+25
200 pixel(jp*5+100,kp*5+100,col)
210 NEXT
220 NEXT
230 col=col+1
240 NEXT
Go to it, matey, and no falling into them and not coming out again...